<?php
include "../config/config.php";

class dbConnect extends config{
    
    protected $_dbhandle;  
    protected $_result;
    protected $config;
        
        
    function __construct(){
    }        
    
    function connect(){
        
        $this->_dbhandle = mysql_connect($mysqlHost, $config->mysqlUsername, $config->mysqlPassword);
        if($this->_dbhandle != 0){
            if(mysql_select_db($config->mysqlDatabase, $this->_dbhandle)){
                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
    
    function disconnect(){
        if(@mysql_close($this->_dbhandle != 0)){
            return 1;
        } else {
            return 0;
        }
    }
    
    function selectAll($table){
        $query = "SELECT * FROM `".$table."`";
        return $this->query($query);
    }
    
    function selectRecordByID($table, $id, $field){
        $query = "SELECT * FROM `".$table."` WHERE ".$field."='".$id."'";
        return $this->query($query);
    }
    
    function query($query){
        if(!$this->_result = mysql_query($this->$_dbhandle)){
            die(mysql_error($this->_dbhandle));
        }
        $num_of_fields = mysql_num_rows($this->_result);
        
        if($num_of_fields > 1){
            $result = mysql_fetch_array($this->_result);
        } else {
            $result = $this->_result;
        }
        return $result;
    }
    
    function getError(){
        return mysql_error($this->_dbhandle);
    }
}

?>